package com.my.test.thread.concurrent;

import java.util.concurrent.Semaphore;

public class MySemaphore {

    static Semaphore se = new Semaphore(5);
    static int count = 0;
    public static void main(String[] args) {
        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                try {
                    se.acquire();
                    count++;
                    Thread.sleep(3000);
                    System.out.println("获得许可证执行:"+Thread.currentThread().getName());
                    se.release();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
